<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<%@ taglib prefix ="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="zh-cn">
	<head>
		<%@ include file="/common/common-css.jsp" %>
		<%@ include file="discovery-css.jsp" %>
	</head>
<body class="no-skin">
	<div class="page-content">
	
			
			<ul class="nav nav-pills discovery-nav" role="tablist">
			  <li role="presentation"><a href="${ctx}/discovery/daily/listdaily.action?pageno=1&pagesize=${pageSize}">全部<!-- <span class="badge">3</span>--></a></li>
			  <li role="presentation"><a href="${ctx}/discovery/daily/listdaily.action?status=1&pageno=1&pagesize=${pageSize}">已发布<!-- <span class="badge">3</span>--></a></li>
			  <li role="presentation"><a href="${ctx}/discovery/daily/listdaily.action?status=0&pageno=1&pagesize=${pageSize}">素材库<!-- <span class="badge">3</span>--></a></li>
			  <li role="presentation"><a href="${ctx}/discovery/daily/listdaily.action?status=1&pageno=1&pagesize=${pageSize}&isspread=true">推广<!-- <span class="badge">3</span>--></a></li>
			  <li role="presentation"><button id="pushreddot">群推小红点</button></li>
			</ul>
			<hr/>
		<div class="page-content-area">
			
			<div class="row">
				<div class="col-xs-12 col-sm-12 widget-container-col">
				    <div style="text-align:right;">
				    </div>
					<div class="widget-box widget-color-blue">
						<!-- #section:custom/widget-box.options.collapsed -->
						<div class="widget-body">
							<div class="widget-main" >
								<div class="row" id="prices">
									<div class="col-xs-12 col-md-12">
										<table class="table table-bordered table-hover table-condensed table-responsive discovery-table" id="hours_price">
											<tr>
											    <th>id</th>
												<th>题图</th>
												<th>标题</th>
												<th>发布时间</th>
												<th>状态</th>
												<th>操作</th>
											</tr>
											<s:iterator value="list" var="obj"> 
                                                 <tr>
                                                <td><b>${obj.id}</b></td>
												<td><img src="${obj.img}"/></td>
												<td><b>${obj.title}</b></td>
												<td>${obj.publishtime}</td>
												
												<td>
													<s:if test='%{#obj.tag == 6}'>
														置顶时间：${obj.updatetime }
													</s:if>
													<s:elseif test='%{#obj.tag == 3}'>
														位置：${obj.topindex }
													</s:elseif>
													<s:else>
														<s:if test='%{#obj.status == "1"}'>已发布</s:if>
	                                                    <s:elseif test='%{#obj.status == "0"}'>素材</s:elseif>
													</s:else>
												</td>
												<td><a class="btn btn-primary" href="${ctx}/discovery/daily/editdaily.action?id=${obj.id}">编辑</a> &nbsp;<a href="../../../discovery_service/common?funid=12&ispage=2&detailid=${obj.id}" 
											 class="btn btn-danger" target="_blank">预览</a>&nbsp;
											 <s:if test='%{#obj.status == "1"}'>
											 	<a data-toggle="" href="${ctx}/discovery/daily/deleteArticle.action?id=${obj.id}&status=0" class="btn btn-danger delete">下线</a>
											 </s:if>
											 <s:elseif test='%{#obj.status == "0"}'>
											 	<a data-toggle="" href="${ctx}/discovery/daily/deleteArticle.action?id=${obj.id}&status=1" class="btn btn-danger delete">上线</a>
											 </s:elseif>
											 
											 </td>
											</tr>
                                            </s:iterator>
										</table>
									</div>
								</div>
								<div class="discovery-pagination">
									  <ul class="pagination">
										<!--每页显示个数-->
									  <span class="discovery-pagination-tit">每页显示</span>
									  <select class="discovery-pagination-select" id="howmany">
									    <option value="25" >25</option>
										<option value="50" >50</option>
										<option value="100">100</option>
									  </select>
									  <span class="discovery-pagination-tit discovery-pagination-tit2">条结果</span>
									  <!--每页显示个数-->
										
										<li class="page-backward">
										  <a href="${ctx}/discovery/daily/listdaily.action?status=${status}&pageno=1&pagesize=${pageSize}" aria-label="First">
											<span class="glyphicon glyphicon-backward"></span>
										  </a>
										</li>
										<li class="page-chevron-left">
										  <a href="javascript:;" aria-label="Previous">
											<span class="glyphicon glyphicon-chevron-left"></span>
										  </a>
										</li>
										<li class="discovery-pagination-page form-group">
											<a class="discovery-pagination-pagenum pagenum1" style="border-top:none;border-bottom:none;border-right:none;color:#434343;float:left;margin-right:1px;">Page</a>
											<input class="discovery-pagination-pagenum pagenum2 form-control" style="width:50px;height:30px;float:left;text-align:center;" type="text" value="${pageNo}" id="pagenum"/>
											<a class="discovery-pagination-pagenum" style="border-top:none;border-bottom:none;border-left:none;color:#434343;float:left">of ${totalPage}</a>
										</li>
										<li class="page-chevron-right">
										  <a href="javascript:;" aria-label="Next">
											<span class="glyphicon glyphicon-chevron-right"></span>
										  </a>
										</li>
										<li class="page-forward">
										  <a href="${ctx}/discovery/daily/listdaily.action?status=${status}&pageno=${totalPage}&pagesize=${pageSize}" aria-label="Last">
											<span class="glyphicon glyphicon-forward"></span>
										  </a>
										</li>
										
										<!--正在查看的结果区间-->
										<b class="discovery-pagination-check">正在查看${totalNum}条结果中的 <span class="current-first">1</span>-<span class="current-last">25</span> 条</b>
										<!--正在查看的结果区间-->

									  </ul>
									 
									</div>
									
							</div><!-- /.widget-main -->
						</div><!-- /.widget-body -->
					</div><!-- /.widget-box -->
				</div><!-- /.col-sm-12 -->
			</div><!-- /.row -->

		</div><!-- /.page-content-area -->
	</div><!-- /.page-content -->
	
	<!--点击删除弹出框start-->
	<!-- 模态框（Modal） --><!--
<div class="modal fade" id="delete" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" 
               data-dismiss="modal" aria-hidden="true">
                  &times;
            </button>
            <h4 class="modal-title" id="myModalLabel">
               确认删除？
            </h4>
         </div>
         <div class="modal-body">
           该篇文章会在后台完全删除。已发布的文章会在列表中消失
         </div>
         <div class="modal-footer">
            <a class="btn btn-default" 
               data-dismiss="modal">取消
            </a>
            <a class="btn btn-primary" id="delete-confirm">
               删除
            </a>
         </div>
      </div>
	</div>  
</div>--><!-- /.modal -->

<div  class="load_bg" ></div>
<img src="http://img.xmiles.cn/commentloading.gif" class="load_img"/>

<style>
.load_bg{background:#000;opacity:0.1;left:0px;top:0px;position:fixed;height:100%;width:100%;overflow:hidden;z-index:10000;display: none;}
.load_img{left:50%;top:180px;position:fixed;height:50px;overflow:hidden;z-index:20000;display: none;}
</style>
	
<%@ include file="/common/common-js.jsp" %>
<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
<script>
  $(function(){
    $('.delete').click(function(){
      var id=$(this).attr('tabindex');
      //$('#delete-confirm').attr('href',id);
	  //$(this).attr('href',id);
	  var conf=confirm("确定执行？");
	  if (conf==true)
		{
		return true;
		}
	  else
		{
		return false;
		}
    });//删除确认
    
    var isspread = '${isspread}'; // 是否推广
	var status = '${status}';//状态(全部,草稿,已发布)
	var pagesize = '${pageSize}';//每页数
	var pageNo = '${pageNo}';//页码
	var pageNo_next = Number(pageNo) + 1;//下一页页码
	var pageNo_prev = Number(pageNo) - 1;//上一页页码
	var totalPage = '${totalPage}';//总页码
	
	if (pagesize == 25) {
		$('#howmany').children("option:nth-child(1)").attr('selected', true);
	} else if (pagesize == 50) {
		$('#howmany').children("option:nth-child(2)").attr('selected', true);
	} else {
		$('#howmany').children("option:nth-child(3)").attr('selected', true);
	}//下拉框选中当前每页数
	
	console.log("isspread" + isspread);
	if (isspread == 'true') {
		$('.discovery-nav').children("li:nth-child(4)").addClass('active');
	} else {
		//状态选中(全部,草稿,已发布)
		if (status == '') {
			$('.discovery-nav').children("li:nth-child(1)").addClass('active');
		} else if (status == 1) {
			$('.discovery-nav').children("li:nth-child(2)").addClass('active');
		} else if (status == 0) {
			$('.discovery-nav').children("li:nth-child(3)").addClass('active');
		}
	}
	
	if(pageNo==1){
		$('.page-backward,.page-chevron-left').addClass('disabled');
	}//当前第一页时第一页与上一页按钮失效
	if(pageNo==totalPage){
		$('.page-chevron-right,.page-forward').addClass('disabled');
	}////当前最后一页时最后一页与下一页按钮失效
	if(pageNo!=1){
		$('.page-chevron-left a').click(function(){
			$(this).attr('href',ctx +'/discovery/daily/listdaily.action?status=${status}&pageno='+pageNo_prev+'&pagesize=${pageSize}')
		});//点击跳转下一页
	}
	if(pageNo!=totalPage){
		$('.page-chevron-right a').click(function(){
		$(this).attr('href',ctx +'/discovery/daily/listdaily.action?status=${status}&pageno='+pageNo_next+'&pagesize=${pageSize}');
	});//点击跳转上一页
	}
	var first = pagesize*(pageNo-1)+1;//获取当前页第一条位置
	$('.current-first').html(first);
	var last = pagesize*pageNo;//获取当前页最后一条位置
	$('.current-last').html(last);
	$('#howmany').change(function(){
		pagesize = $(this).val();
		window.location.href=ctx +"/discovery/daily/listdaily.action?status="+status+"&pageno=${pageNo}&pagesize="+pagesize;
	});//下拉框改变每页数
	$('.pagenum2').blur(function(){
	  if($(this).val()>totalPage){
	    window.location.href=ctx + "/discovery/daily/listdaily.action?status="+status+"&pageno="+totalPage+"&pagesize=${pageSize}"; 
	  }else{
		window.location.href=ctx + "/discovery/daily/listdaily.action?status="+status+"&pageno="+$(this).val()+"&pagesize=${pageSize}";
	  }
	});//鼠标离开页码输入框时跳转到该页码

	$('#templet-refresh').click(function() {
        $('.load_bg,.load_img').show();
		$.ajax({
		  type: 'POST',
		  url: ctx+"/discovery/article/onekeyrefresh.action",
		  complete: function(){
			 $('.load_bg,.load_img').hide(); 
		  }
		});  
	});
	
	$("#pushreddot").click(function() {
		 var con = confirm("确定群推给所有用户？？");
		 if (con == true) {
				$(".load_bg,.load_img").show();
				$.get("./pushRedDot.action?userid=364229", function(data) {
					  // alert("Data Loaded: " + data);
					  alert(data);
					  $(".load_bg,.load_img").hide();
				});
		 }
	});
  })
</script>	
</body>
</html>
